export default {
	data() {
		return {

		}
	},
	computed: {
		mingge() {
			let str = this.detail.detail_info.sizhu_info.sizhu_indication.wuxing.detail_desc
			if (str) {
				return str.substr(4, str.length)
			}
			return ''
		},
		mingyun() {
			return this.getTwelveVal() + '格· ' + this.mingge
		},
		rizhutiangan() {
			return this.detail.detail_info.sizhu_info.day.tg
		},
		yuezhudizhi() {
			return this.detail.detail_info.sizhu_info.month.dz
		},
		sizhuInfo() {
			return this.detail.detail_info.sizhu_info
		}
	},
	filters: {
		toFixed1(val) {
			var num = val.split('%')[0]
			if (num == 0) {
				return num
			} else {
				return Number(num).toFixed(1)
			}
	
		}
	},
	onShow() {

	},


	methods: {
		getTwelveVal() {
			if (this.rizhutiangan === '甲' && this.yuezhudizhi === '寅') { // 规则1
				return '建禄'
			} else if (this.rizhutiangan === '乙' && this.yuezhudizhi === '卯') {
				return '建禄'
			} else if (this.rizhutiangan === '丙' && this.yuezhudizhi === '巳') {
				return '建禄'
			} else if (this.rizhutiangan === '丁' && this.yuezhudizhi === '午') {
				return '建禄'
			} else if (this.rizhutiangan === '庚' && this.yuezhudizhi === '申') {
				return '建禄'
			} else if (this.rizhutiangan === '庚' && this.yuezhudizhi === '申') {
				return '建禄'
			} else if (this.rizhutiangan === '辛' && this.yuezhudizhi === '酉') {
				return '建禄'
			} else if (this.rizhutiangan === '壬' && this.yuezhudizhi === '亥') {
				return '建禄'
			} else if (this.rizhutiangan === '癸' && this.yuezhudizhi === '子') {
				return '建禄'
			} else if (this.rizhutiangan === '乙' && this.yuezhudizhi === '寅') { // 规则2
				return '劫月'
			} else if (this.rizhutiangan === '丁' && this.yuezhudizhi === '巳') {
				return '劫月'
			} else if (this.rizhutiangan === '辛' && this.yuezhudizhi === '申') {
				return '劫月'
			} else if (this.rizhutiangan === '癸' && this.yuezhudizhi === '亥') {
				return '劫月'
			} else {
				const yearArr = this.sizhuInfo.year.wx.split('')
				const monthArr = this.sizhuInfo.month.wx.split('')
				const hourArr = this.sizhuInfo.hour.wx.split('')
				const dayArr = this.sizhuInfo.day.wx.split('')
		
				// 除开日柱天干以外的其他7个年柱、月柱、日柱、时柱的天干地支
				const tempArr = [...yearArr, ...monthArr, ...hourArr, dayArr[1]]
				console.log('日柱天干:' + dayArr[0], '-------其他7个年柱、月柱、日柱、时柱的天干地支:' + tempArr, '判定3')
				// 规则3 相生
				const isXiangsheng = this.xiangsheng(dayArr[0], tempArr)
		
				// 规则4 相克
				const isXiangke = this.xiangke(dayArr[0], tempArr)
		
				// 判定5
				const jungeleFiveData = this.jungleFive()
				
				// 判定6
				const yuezhugods = this.sizhuInfo.month.dz_god // 月柱的主星十神
				const notUseArr = ['比肩', '劫财']
				const jungeleSixData = this.jungeleSix(yuezhugods, notUseArr)
				
				// 判定7
				const jungeleSevenData = this.jungleSeven(yuezhugods, notUseArr)
		
				if (isXiangsheng) {
					return '从强'
				} else if (isXiangke) {
					return '从弱'
				} else if (jungeleFiveData.flag) {
					return jungeleFiveData.str
				} else if (jungeleSixData) {
					return jungeleSixData
				} else {
					return jungeleSevenData
				}
			}
		
		},
		// 相生和相同
		xiangsheng(val, arr) {
			console.log(val, arr, 'xiangsheng')
			// 五行相生：金生水，水生木，木生火，火生土，土生金，
			const wxArr = ['金', '水', '木', '火', '土']
			let curIdx = wxArr.findIndex(item => item === val)
			let xsVal = '' // 相生的值
			if (curIdx === 0) {
				xsVal = wxArr[wxArr.length - 1]
			} else {
				xsVal = wxArr[curIdx - 1]
			}
			const isXs = this.checkArr(val, xsVal, arr) // 是否相生
			return isXs
		},
		// 相克
		xiangke(val, arr) {
			// 五行相克：金克木、木克土、土克水、水克火、火克金
			const wxArr = ['火', '金', '木', '土', '水']
			let curIdx = wxArr.findIndex(item => item === val)
			let xkVal = '' // 相克的值
			if (curIdx === 0) {
				xkVal = wxArr[wxArr.length - 1]
			} else {
				xkVal = wxArr[curIdx - 1]
			}
			const isXk = arr.every(item => item === xkVal) // 是否相克
			return isXk
		},
		checkArr(val, sameVal, arr) {
			let aCount = 0;
			let bCount = 0;
			for (let i = 0; i < arr.length; i++) {
				if (arr[i] === val) {
					aCount++;
				} else if (arr[i] === sameVal) {
					bCount++;
				} else {
					return false;
				}
			}
			return arr.length === aCount + bCount;
		},
		// 判定规则5
		jungleFive() {
			let str = '',
				flag = false
			const month = this.sizhuInfo.month
			const yuezhucanggan = month.cg // 月柱的藏干
			const yuezhugod = month.dz_god // 月柱的主星十神
			const nianyueritg = [this.sizhuInfo.year.tg, month.tg, this.sizhuInfo.hour.tg] // 年柱-天干、月柱-天干、时柱-天干
		
			// -------------- 判定5 测试数据  --------------
		
			// 月柱的藏干
			// const yuezhucanggan = ['癸', '申', '辛'] 
			// // 年柱-天干、月柱-天干、时柱-天干
			// const nianyueritg = ['甲', '申', '辛']
			// // 月柱的主星十神
			// const yuezhugod = ['比肩', '劫财', '正财'] 
		
			console.log('月柱的藏干:' + yuezhucanggan, '-----年、月、日柱天干:' + nianyueritg, '-----月柱的主星十神:' + yuezhugod)
			for (var i = 0; i < yuezhucanggan.length; i++) {
				var item = yuezhucanggan[i];
		
				if (nianyueritg.includes(item)) {
					if (yuezhugod[i] != '比肩' && yuezhugod[i] != '劫财') {
						flag = true
						str = yuezhugod[i]
						break
					}
				}
		
			}
			return {
				flag,
				str
			}
		},
		// 判定规则6
		jungeleSix(arr, targetValues) {
			if (arr.length === 1) {
				if (!targetValues.includes(arr[0])) {
					return arr[0]
				}
			} else {
				for (let i = 0; i < arr.length; i++) {
					if (!targetValues.includes(arr[i])) {
						// 返回当前元素的下一个元素
						return arr[i];
					}
				}
			}
		
			return undefined;
		},
		
		// 判定规则7 上述6种都无法确认，如果藏干是劫财的话就叫月劫格，如果藏干是比肩就叫建禄格
		jungleSeven(arr) {
			if (arr.length === 1) {
				if (arr[0] === '劫财') {
					return '月劫'
				} else if (arr[0] === '比肩') {
					return '建禄'
				}
			}
			return ''
		}
				
	}
}